package com.yupi.yupao.config;

import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: Peter
 * @Date: 2024-05-04-11:20
 * @Description: Pe
 */
@Configuration
@ConfigurationProperties(prefix = "spring.redis")
@Data
public class RedissionConfig {
    private String host;
    private  String port;
    @Bean
    public RedissonClient redissonClient() {
        //配置
        Config config = new Config();
        String redisAddress = String.format("redis://%s:%s", host, port);
        config.useSingleServer().setAddress(redisAddress).setDatabase(3);
        //  使用单个Redis，没有开集群 useClusterServers()  设置地址和使用库config.useSingleServer()

        //创建RedissonClient对象
        return Redisson.create(config);
    }

}
